<% include header %>
<body>
<nav class="navbar navbar-inverse  navbar-fixed-top" id="index-nav">
    <div class="container">
        <div class="navbar-header">
            <button class="navbar-toggle" data-target="#mynavbar_list" data-toggle="collapse" aria-expanded="false"
                    aria-controls="navbar">
                <span class="sr-only">Toggle navigation</span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
            </button>
            <a href="/" class="navbar-brand">sdhBlog</a>
        </div>
        <div id="mynavbar_list" class="collapse  navbar-collapse">
            <ul class="nav navbar-nav">
                <li><a href="/">主页</a></li>
            </ul>
            <!--搜索表单-->
            <form action="/askSearch" method="get" class="navbar-form navbar-left" role="form">
                <input type="text" name="keyword" placeholder="search" class="form-control"/>
            </form>
            <ul class="nav navbar-nav navbar-right hidden-sm">
                <!--登录状态-->
                <% if(user) { %>
                <li>
                    <a href="userInfo" class="navbar-link userInfo">
                        <img src="/uploads/<%= user.picUrl %>" alt="" onerror="this.src='uploads/default.jpg'">
                        <%= user.name %>
                    </a>
                </li>
                <li><a href="ask" class="navbar-link padding-left">提问</a></li>
                <li><a href="logout" class="navbar-link">退出</a></li>
                <!--未登录状态-->
                <% } else{ %>
                <li><a href="/reg" class="navbar-link padding-left">注册</a></li>
                <li><a href="/login" class="navbar-link">登录</a></li>
                <% } %>
            </ul>
        </div>
    </div>
</nav>
<div class="container bg-index">
    <% asks.forEach(function (ask) { %>
    <div class="allAsk col-xs-12">
        <!--用户头像-->
        <img src="/uploads/<%= ask.picUrl %>" alt="" onerror="this.src='uploads/default.jpg'">
        <a href="/u/<%= ask.name %>/<%= ask.time.second %>/<%= ask.askTitle %>"
           class="askContent"><%= ask.askTitle %></a>
        <p class="pull-right">发布于 <%= ask.time.day %></p>
    </div>
    <% }) %>
    <div class="askEmpty col-xs-12"></div>
</div>

</body>
<% include paging %>
<% include footer %>
<script>
    //如果用户没有登录注册,提示用户登录注册
    //如果已登录,提示用户发表
    $(function () {
        var length = $('.allAsk').length;
        var user = '<%= user %>';
        if (user) {
            if (length == 0) {
                $('.askEmpty').css('display', 'block').html('在这里你可以畅所欲言,不敢说出的小秘密,困扰了很久的烦心事,都会有人帮你解决...请开启你的心路旅程吧O(∩_∩)O~');
            } else {
                $('.askEmpty').css('display', 'none');
            }
        } else {
            if (length == 0) {
                $('.askEmpty').css('display', 'block').html('欢迎来到颂宋的博客O(∩_∩)O~,等你好久了,悄悄告诉你注册登录有惊喜呦!');
            } else {
                $('.askEmpty').css('display', 'none');
            }
        }
        //如果当前没有人提问 不显示分页容器
        if (length == 0) {
            $('.paging').css('display', 'none')
        } else {
            $('.paging').css('display', 'block')
        }
    })
</script>